// pages/dingdan/dingdan.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid:'',
    dingdanList:[
      {
        id:1,
        img:'/tupian/分类/1.webp',
        mingzi:'汉服儿童女短袖连衣裙',
        num:1,
        feiyong:120,
        time:1,
        day:"天"
    }
  ],
  feiyong:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
this.setData({
  openid:wx.getStorageSync('openid')
})
this.genxin();
    },
      

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  sanchu:function(e){
    console.log(e.target.dataset.index)
    wx.request({
      url: 'http://localhost:80/reserve/deleteOne',
      method:"POST",
      data:{
        user_openid:this.data.openid,
        articlesid:e.target.dataset.index
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000//持续的时间
      })
      this.genxin()
    }
    })
  },
  Alldelete:function(){
    wx.request({
      url: 'http://localhost:80/reserve/deleteAll',
      method:"POST",
      data:{
        user_openid:this.data.openid
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        wx.showToast({
          title: '成功',
          icon: 'success',
          duration: 2000//持续的时间
        })
        this.genxin()
      }
    })
  },
  genxin(){
    wx.request({
      url: 'http://localhost:80/dingdan/openid',
      method:"POST",
      data:{
        user_openid:this.data.openid
      },
      header:{
        'content-type': 'application/x-www-form-urlencoded'
    },
    success:res=>{
      this.setData({
        dingdanList:res.data.data
      })
      console.log(this.data.dingdanList)
      var i=0,money=0;
      for(i=0;i<this.data.dingdanList.length;i++){
          money=money+this.data.dingdanList[i].feiyong;
      }
      this.setData({
        feiyong:money
      })
      console.log(this.data.feiyong)
    }
    })
  },
  jiesuan:function(e){
    var a=this.data.dingdanList.length
    var i=0;
    for(i;i<a;i++){
      wx.request({
        url: 'http://localhost:80/lease/insert',
        method:"POST",
        data:{
          user_openid:this.data.openid,
          articlesid:this.data.dingdanList[i].id,
          leixin:this.data.dingdanList[i].leixin,
          starttime:this.data.dingdanList[i].starttime,
          overtime:this.data.dingdanList[i].overtime,
          number:this.data.dingdanList[i].number,
          feiyong:this.data.dingdanList[i].feiyong
        },
        header:{
          'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        if(res.data.msg=="添加成功"){
          wx.navigateTo({
          url: '/pages/zhifu/zhifu?resultType=success',
        })
        }else{
          wx.navigateTo({
          url: '/pages/zhifu/zhifu?resultType=error',
        })
        }
      }
      })
    }
    console.log(a)
  }
})